Object-Oriented Programming with C++ by A.K. Sharma

Object-Oriented Programming with C++ by A.K. Sharma

Author:A.K. Sharma [A.K. Sharma]
Language: eng
Format: epub
Publisher: Pearson India
Published: 2013-12-31T16:00:00+00:00


Figure 6.2 Object copy operation through assignment operator

Now, this abnormal situation would cause many types of problems such as both the objects work on the same location, the changes done by one object to the common location may not be acceptable to another object, etc.

Thus, for copying objects with pointers, we need a mechanism that allows member-wise copy of the objects so that separate space may be allocated to the pointer of the target object.

C++ provides a special constructor called copy constructor that allows the programmer to member-wise copy of one object to another. However, the programmer must write the code for member-wise copy of various members of the source object to the corresponding members of the target object. The copy constructor is, however, defined in the class as a parameterized constructor receiving an object of its own type as argument passed by reference. Consider the class given below:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.